package gat.api.rest.oss;

import javax.annotation.Resource;

import com.alibaba.fastjson.JSONObject;
import gat.common.util.TencentCosUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bitsun.core.common.annotation.SkipLogin;
import com.bitsun.core.common.web.ResultDTO;
import gat.api.oss.OssApi;
import gat.common.util.OssUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 文件上传
 * @author sxq
 * @date 2022/2/10
 */

@Slf4j
@RestController
@SkipLogin
@RequestMapping("/oss")
public class OssController implements OssApi {

    @Resource
    private OssUtil ossUtil;
    @Resource
    private TencentCosUtil tencentCosUtil;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @Override
    @PostMapping(value = "/uploadFile", consumes = "multipart/*", headers = "content-type=multipart/form-data")
    public ResultDTO<String> uploadFile(MultipartFile file) {

        String path = ossUtil.uploadFile(file);
        return ResultDTO.ok(path);
    }

}
